{% extends "base.html" %}
{% block header %}
<script type="text/javascript">
    var error_name =  true;
    var error_pwd = true;
	$(function () {
	    $('.footer').css({"margin-top":"0px"});
        $('.footer').addClass("no-mp");
		$('#username').blur(function () {
			check_username();
        });

		$('#pwd').blur(function () {
			check_pwd();
        });
		$('#username').focus(function () {
		    $('.user_error').hide();
        });

		$('#pwd').focus(function () {
		    $('.pwd_error').hide();
        });
		// if(0=={{error_user}}){
	     //    $('.user_error').html("用户名不存在！").show()
		// }
        var error_user = $('#error_user').html();
        var error_pwd = $('#error_pwd').html();
		if('1' == error_user){
		   $('.user_error').html("用户名不存在！").show()
		}
		if('1' == error_pwd){
		   $('.pwd_error').html("密码错误！").show()
		}


    });

	function check_username() {
		var len = $('#username').val().length;
		if(0 == len){
		    $('.user_error').html("请输入用户名！").show();
		} else {
            $('.user_error').hide();
            error_name = false;
		}
    }

    function check_pwd() {
		var len = $('#pwd').val().length;
		if(0 == len){
		    $('.pwd_error').html("请输入密码！").show();
		} else {
            $('.pwd_error').hide();
            error_pwd = false;
		}
    }

    function check_submit() {
	    check_username();
	    check_pwd();
	    if(error_name == false && error_pwd == false){
	        return true;
		} else {
	        return false;
		}
	}
</script>
{% endblock header %}

{% block body%}
	<div class="login_top clearfix">
		<a href="/goods/index" class="login_logo"><img src="/static/images/logo02.png"></a>
	</div>

	<div class="login_form_bg">
		<div class="login_form_wrap clearfix">
			<div class="login_banner fl"></div>
			<div class="slogan fl">日夜兼程 · 急速送达</div>
			<div class="login_form fr">
				<div class="login_title clearfix">
					<h1>用户登录</h1>
					<a href="/user/register/">立即注册</a>
				</div>
				<div class="form_input">
					<form action="/user/login_handler/" method="post" onsubmit="return check_submit()">
						{%csrf_token%}
						<input type="text" name="username" id="username" value="{{user_name}}" class="name_input" placeholder="请输入用户名">
						<div class="user_error">输入错误</div>
						<input type="password" name="pwd" id="pwd" value="{{pwd}}" class="pass_input" placeholder="请输入密码">
						<div class="pwd_error">输入错误</div>
						<div class="more_input clearfix">
							<input type="checkbox" id="remember" name="remember" value="1" checked="checked">
							<label>记住用户名</label>
							<a href="#">忘记密码</a>
						</div>
						<input type="submit" name="" value="登录" class="input_submit">
					</form>
                    <span hidden="hidden" id="error_user">{{error_user}}</span>
					<span hidden="hidden" id="error_pwd">{{error_pwd}}</span>
				</div>
			</div>
		</div>
	</div>

{% endblock body %}
